import { FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table';
import { formatToDateTime } from '/@/utils/dateUtil';
import { PagePlanInputDto, PlansServiceProxy, IdInput } from '/@/services/ServiceProxies';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();

export const searchFormSchema: FormSchema[] = [
    {
        field: 'filter',
        label: t('common.key'),
        component: 'Input',
        colProps: { span: 8 },
    },
];

export const tableColumns: BasicColumn[] = [
    {
        title: t('routes.production.plan.planSerialNum'),
        dataIndex: 'planSerialNum',
    },
    {
        title: t('routes.production.plan.smeltNo'),
        dataIndex: 'smeltNo',
    },
    {
        title: t('routes.production.plan.steelType'),
        dataIndex: 'steelType',
    },
    {
        title: t('routes.production.plan.tappingTemperature'),
        dataIndex: 'tappingTemperature',
    },
    {
        title: t('routes.production.plan.smeltingProcess'),
        dataIndex: 'smeltingProcess',
    },
    {
        title: t('routes.production.plan.specialProcessRequirement'),
        dataIndex: 'specialProcessRequirement',
    },
    {
        title: t('routes.production.plan.planStartTime'),
        dataIndex: 'planStartTime',
    },
    {
        title: t('routes.production.plan.planEndTime'),
        dataIndex: 'planEndTime',
    },
    {
        title: t('routes.production.plan.realStartTime'),
        dataIndex: 'realStartTime',
    },
    {
        title: t('routes.production.plan.realEndTime'),
        dataIndex: 'realEndTime',
    },
    {
        title: t('common.creator'),
        dataIndex: 'creatorName',
    },
    {
        title: t('common.creationTime'),
        dataIndex: 'creationTime',
        customRender: ({ text }) => {
            return formatToDateTime(text);
        }
    },
    {
        title: t('common.lastModifier'),
        dataIndex: 'LastModifierName',
    },
    {
        title: t('common.lastModificationTime'),
        dataIndex: 'lastModificationTime',
        customRender: ({ text }) => {
            return formatToDateTime(text);
        }
    }
];

export const createFormSchema: FormSchema[] = [
    {
        field: 'smeltNo',
        label: t('routes.production.plan.smeltNo'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'steelType',
        label: t('routes.production.plan.steelType'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'tappingTemperature',
        label: t('routes.production.plan.tappingTemperature'),
        component: 'InputNumber',
        required: true,
        colProps: { span: 18 },
        componentProps: {
            min: 0,
            step: 0.1
        }
    },
    {
        field: 'smeltingProcess',
        label: t('routes.production.plan.smeltingProcess'),
        component: 'Input',
        required: true,
        colProps: { span: 18 }
    },
    {
        field: 'specialProcessRequirement',
        label: t('routes.production.plan.specialProcessRequirement'),
        component: 'Input',
        required: false,
        colProps: { span: 18 }
    }
];

export const updateFormSchema: FormSchema[] = [
    {
        field: 'id',
        label: 'Id',
        component: 'Input',
        ifShow: false,
        colProps: { span: 18 },
    },
    {
        field: 'smeltNo',
        label: t('routes.production.plan.smeltNo'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'steelType',
        label: t('routes.production.plan.steelType'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'tappingTemperature',
        label: t('routes.production.plan.tappingTemperature'),
        component: 'InputNumber',
        required: true,
        colProps: { span: 18 },
        componentProps: {
            min: 0,
            step: 0.1
        }
    },
    {
        field: 'smeltingProcess',
        label: t('routes.production.plan.smeltingProcess'),
        component: 'Input',
        required: true,
        colProps: { span: 18 }
    },
    {
        field: 'specialProcessRequirement',
        label: t('routes.production.plan.specialProcessRequirement'),
        component: 'Input',
        required: false,
        colProps: { span: 18 }
    }
];

export async function createAsync({ params }) {
    const plansServiceProxy = new PlansServiceProxy();
    await plansServiceProxy.create(params);
}

export async function updateAsync({ params }) {
    const plansServiceProxy = new PlansServiceProxy();
    await plansServiceProxy.edit(params);
}

export async function deleteAsync({ id }) {
    const plansServiceProxy = new PlansServiceProxy();
    const request = new IdInput();
    request.id = id;
    await plansServiceProxy.delete(request);
}

export async function getTableListAsync(params: PagePlanInputDto) {
    const plansServiceProxy = new PlansServiceProxy();
    return plansServiceProxy.page(params);
}